<%@ page import="org.apache.ibatis.session.SqlSession" %>
<%@ page import="myschool.util.MybatisUtil" %>
<%@ page import="myschool.dao.StudentDao" %>
<%@ page import="myschool.entity.Student" %>
<%@ page import="java.util.List" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="javax.print.DocFlavor" %>
<%@ page import="myschool.biz.StudentService" %>
<%@ page import="myschool.util.StrUtil" %>
<%@ page import="java.util.Date" %><%--
  Created by IntelliJ IDEA.
  User: oldliu
  Date: 2023-04-06
  Time: 8:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>学生列表</title>
    <script src="js/jquery-3.6.3.min.js"></script>
</head>
<body>
<p>
   <a href="addstudent.jsp">增加学生</a>
</p>
<%
    String sname = StrUtil.toStr(request.getParameter("sname"));
    String tel = StrUtil.toStr(request.getParameter("tel"));
    Date start = StrUtil.toDate(request.getParameter("dateStart"));
    Date end = StrUtil.toDate(request.getParameter("dateEnd"));
    //int pageNo=1;
    int pageNo = StrUtil.toInt(request.getParameter("pageNo"), 1);
    int pageSize = 10;

    List<Student> list = StudentService.ME.search1(sname, tel, start, end, pageNo, pageSize);
    int size = StudentService.ME.search1Total(sname, tel, start, end);
    //总共多少页
    int pageTotal = (size / pageSize) + (size % pageSize == 0 ? 0 : 1);

%>
<p>
<form action="students.jsp" method="get" id="searchForm">
    <input type="hidden" name="pageNo" value="1"/>
    <input type="text" placeholder="姓名" name="sname" value="<%=sname%>"/>
    <input type="text" placeholder="电话" name="tel" value="<%=tel%>"/>
    入学时间从<input type="date" placeholder="yyyy-MM-dd" name="dateStart" value="<%=StrUtil.toStr(start)%>"/>
    -<input type="date" placeholder="yyyy-MM-dd" name="dateEnd" value="<%=StrUtil.toStr(end)%>"/>

    <input type="submit" value="搜索"/>
</form>
</p>
<table border="1" cellpadding="0" cellspacing="0">
    <tr>
        <th>学号</th>
        <th>姓名</th>
        <th>QQ</th>
        <th>Wechat</th>
        <th>手机</th>
        <th>性别</th>
        <th>入学时间</th>
        <th>操作</th>
    </tr>

    <%
        for (Student stu : list) {
    %>
    <tr>
        <td><%=stu.getStuno()%>
        </td>
        <td><%=stu.getSname()%>
        </td>
        <td><%=stu.getQQ()%>
        </td>
        <td><%=stu.getWechat()%>
        </td>
        <td><%=stu.getTelephone()%>
        </td>
        <td><%=stu.getSex()%>
        </td>
        <td><%=stu.getEnterdate()%>
        </td>
        <td><a href="getStu.do?stuno=<%=stu.getStuno()%>">修改</a>&nbsp;<a onclick="return confirm('真的要删除？')"
                                                                                 href="delStudent.jsp?stuno=<%=stu.getStuno()%>">删除</a>&nbsp;
            <a href="#">查看成绩</a>
        </td>
    </tr>
    <%}%>
</table>
<div id="pager">
    <a href="#" data-page="1">第一页</a>
    <a href="#" data-page="<%=pageNo-1%>">上一页</a>
    <input type="number" value="<%=pageNo%>" max="<%=pageTotal%>" min="1" style="width: 40px"/>
    <button id="go" type="button">Go</button>
    <a href="#" data-page="<%=pageNo+1%>">下一页</a>
    <a href="#" data-page="<%=pageTotal%>">最后一页</a>
    共有<%=size%>人
</div>
<script>
    $(function () {
        $("#pager #go").click(function () {
            let p=$(this).prev().val();
            if(p<1)
                return;
            if(p><%=pageTotal%>)
                return;

            $("#searchForm [name=pageNo]").val(p);
            $("#searchForm").submit();
            return false;
        });
       $("#pager a").click(function () {
           let p=$(this).attr("data-page");
           if(p<1)
               return;
           if(p><%=pageTotal%>)
               return;

           $("#searchForm [name=pageNo]").val(p);
           $("#searchForm").submit();
           return false;
       });
    });
</script>
</body>
</html>
